package com.example.maybeaccount.Mode;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;

import com.example.maybeaccount.ActivityShowDetails;
import com.example.maybeaccount.AddItem;
import com.example.maybeaccount.Chart;
import com.example.maybeaccount.Entry.NineGridUnlock;
import com.example.maybeaccount.MainActivity;
import com.example.maybeaccount.MemberChartActivity;

import java.util.List;
/**
 * 控制后台唤醒解锁后的活动去向
 */
public class ActivityController {
    public static void resumeActivity(Activity activity, Context context){
        Intent intent = activity.getIntent();
        if(intent == null){
            intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
        }else{
            String flag = intent.getStringExtra("resume");
            Item item = (Item)intent.getSerializableExtra("item");
            if(flag == null){
                intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                activity.startActivity(intent);
            }else if(flag.equals("Main")){
                intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                activity.startActivity(intent);
            }else{
                activity.finish();
            }
            /*
            if(flag != null && flag.equals("AddItem")){
                //intent = new Intent(context, AddItem.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                //activity.startActivity(intent);
                activity.finish();
            }else if(flag != null && flag.equals("Chart")) {
                //intent = new Intent(context, Chart.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                //activity.startActivity(intent);
                activity.finish();
            }else if(flag != null && flag.equals("Member")) {
                //intent = new Intent(context, MemberChartActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                //activity.startActivity(intent);
                activity.finish();
            }else if(flag != null && flag.equals("ShowDetails")) {
                    //intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    //intent.putExtra("item",item);
                    //activity.startActivity(intent);
                activity.finish();
            }else{
                intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                activity.startActivity(intent);
            }*/
        }
    }
    /**
     * 检测某Activity是否在当前Task的栈顶
     */
}
